package com.example.zhaoping.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Value("${pathPatterns}") //调用“application.yml” 文件的全局变量pathPatterns
    private String pathPatterns = "";

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //静态资源访问
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //http://localhost:8080/demo/user_img/images.png => d:/demo/user_img/images.png
        registry.addResourceHandler("/upload/**").addResourceLocations(pathPatterns);
    }

}
